const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    total_page: 1,
    record_list: [],
    index: 1,
    statistics: {},
    profit_list: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getData();
    this.get_record();
  },

  get_profit(page = 1) {
    app._postNetWork({
      url: app.getNetAddresss("plugin.map-marker.frontend.controllers.member.profit-record.profit"),
      data: {
        page
      },
      success: resdata => {
        let {
          result,
          msg,
          data
        } = resdata.data;
        if (!result) {
          app.tips(msg);
        }
        this.data.page = data.current_page;
        this.data.total_page = data.last_page;
        if (page == 1) {
          this.setData({
            profit_list: data.data
          })
        } else {
          let profit_list = this.data.profit_list.concat(data.data);
          this.setData({
            profit_list
          })
        }
      }
    })
  },
  get_record(page = 1) {
    app._postNetWork({
      url: app.getNetAddresss("plugin.map-marker.frontend.controllers.member.profit-record.record"),
      data: {
        page
      },
      success: resdata => {
        let {
          result,
          msg,
          data
        } = resdata.data;
        if (!result) {
          app.tips(msg);
        }
        this.data.page = data.current_page;
        this.data.total_page = data.last_page;
        if (page == 1) {
          this.setData({
            record_list: data.data
          })
        } else {
          let record_list = this.data.record_list.concat(data.data);
          this.setData({
            record_list
          })
        }
      }
    })
  },
  getData() {
    app._getNetWork({
      url:app.getNetAddresss("plugin.map-marker.frontend.controllers.member.index"),
      success:resdata=>{
        let {
          result,
          msg,
          data
        } = resdata.data;
        if (!result) {
          return app.tips(msg);
        }
        this.setData({statistics:data.statistics})
      }
    })
    
  },
  change(e) {
    let index = e.currentTarget.dataset.index;
    this.setData({index})
    this.data.page = 1;
    index == 1 ? (this.get_record()) : (this.get_profit());
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.page >= this.data.total_page) {
      return
    }
    let page = this.data.page + 1;

    if (this.data.index == 1) {
      this.get_record(page)
    } else {
      this.get_profit(page);
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})